package pro.softzhang.algo.lc100;

public class LC115_DistinctSubsequences {
    public static void main(String[] args) {

    }

    static class Solution {
        public int numDistinct(String s, String t) {
            int[][] dp = new int[s.length() + 1][t.length() + 1];
            dp[0][0] = 1;
            for (int i = 0; i < s.length(); i++) {
                dp[i + 1][0] = 1;
                for (int j = 0; j <= i && j < t.length(); j++) {
                    if(s.charAt(i) == t.charAt(j)) {
                        dp[i + 1][j + 1] = dp[i][j] + dp[i][j + 1];
                    } else {
                        dp[i + 1][j + 1] = dp[i][j + 1];
                    }
                }
            }
            return dp[s.length()][t.length()];
        }
    }
}
